<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>鲜花类型列表</title>
		<link rel="stylesheet" href="../res/layui/css/layui.css" media="all">
		<script src="../res/js/jquery-3.1.1.min.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript" src="../res/js/Tools.js"></script>
		<script src="../res/layui/layui.js" charset="utf-8"></script>
		<script>
			$.ajaxSetup({
				async : false
			});
		</script>
	</head>
	<body>
	        <div class="layui-col-md10">
				<form style="margin-top: 20px;" class="layui-form" id="formId" lay-filter="example">
					<!--隐藏字段id,区分添加和修改-->
					<input type="hidden" name="ftId" id="ftId"/>
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">鲜花类型名称</label>
					   <div class="layui-inline">
					      <input type="text" name="ftName" style="width: 280px;      "  lay-verify="required"  Maxlength="50"  id="ftName "   lay-verify="title" autocomplete="off" placeholder="请输入鲜花类型名称" class="layui-input">
					   </div>
					 </div>
					</div>
						<div class="layui-inline">
							<label class="layui-form-label">鲜花类型内容</label>
					   <div class="layui-inline" >
					      <textarea   type="text" name="ftNeirong" style="width:300px; "  lay-verify="required"  Maxlength="50"  id="ftNeirong"    lay-verify="title" autocomplete="off" placeholder="请输入鲜花类型内容" class="layui-textarea"></textarea>
					   </div>
					 </div>
					<div class="layui-form-item" style="margin-top:40px" id="check">
					   <div class="layui-input-block">
					       <button class="layui-btn  layui-btn-submit " type="submit" name="btn" lay-submit="" lay-filter="formDemo" >立即提交</button>
					       <button class="layui-btn layui-btn-primary" id="closeOne">关闭窗口</button>
					   </div>
					 </div>
				</form>
			</div>
	 <script>
		var  table2;
	 layui.use(['jquery','form','layer','table'],function() {
		 var form = layui.form;
		 var layer=layui.layer;
		 var table=layui.table;
		 var $=layui.$;
		 var index;
		 //提交表单
		 form.on('submit(formDemo)', function (data) {
			// var formData = new FormData(document.getElementById("formId"));
			 var fd = new FormData();
			 var formData = new FormData($("#formId")[0]);
			 $.ajax({
				 cache : true,
				 url: '../flowertype/addOrUpdate ',
				 type: 'post',
				 async : false,
				 data:formData,
				 contentType: false,   //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作，从而失去分界符，而使服务器不能正常解析文件
				 processData: false,   //当设置为true的时候,jquery ajax 提交的时候不会序列化 data，而是直接使用data
				 success: function (index) {
					 //layer.close(index);//关闭弹出层
					 var addIndex = parent.layer.getFrameIndex(window.name);
					 window.parent.layer.close(addIndex);
					 window.parent.table2.reload('tableReload');//数据表格重载
				 }
			 });
			 return false;
		 	});


			 var id = getQueryString("id");
				 if (id) {
					 findById();
			 }
			 //关闭添加产品页面
			 $("#closeOne").click(function() {
				 var addIndex = parent.layer.getFrameIndex(window.name);
				 window.parent.layer.close(addIndex);
				 $('#ftName').val('');
				 $('#ftNeirong').val('');
			 });
		 //修改页面的赋值
		 function findById(){
			 var id=getQueryString("id");
			 var url="../flowertype/findById";
			 var data={ftId:id};
			 $.post(url,data,function(obj){
				 /*$("#ftName").val(obj.ftName);
				 $("#ftNeirong").val(obj.ftNeirong);*/
				 form.val("example",obj);

			 },"json");

		 }

	 });




	 </script>
	</body>
</html>
